<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Calls callbacks for pending operations</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.zookeeper-dispatch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">zookeeper_dispatch</h1>
  <p class="verinfo">(PECL zookeeper &gt;= 0.4.0)</p><p class="refpurpose"><span class="refname">zookeeper_dispatch</span> &mdash; <span class="dc-title">Calls callbacks for pending operations</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.zookeeper-dispatch-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>zookeeper_dispatch</strong></span>
    ( <span class="methodparam">void</span>
   ) : <span class="type"><span class="type void">void</span></span></div>


  <p class="para rdfs-comment">
   The <span class="function"><strong>zookeeper_dispatch()</strong></span> function calls the callbacks passwd by operations like <span class="methodname"><a href="zookeeper.get.html" class="methodname">Zookeeper::get()</a></span> or <span class="methodname"><a href="zookeeper.exists.html" class="methodname">Zookeeper::exists()</a></span>.
  </p>

  <div class="caution"><strong class="caution">Caution</strong>
   <p class="para">
    Since version 0.4.0, this function must be called manually to achieve asynchronous operations. If you want that to be done automatically, you also can declare ticks at the beginning of your program.
   </p>
  </div>

  <p class="para">
   After PHP 7.1, you can ignore this function. This extension uses EG(vm_interrupt) to implement async dispatch.
  </p>

 </div>


 <div class="refsect1 errors" id="refsect1-function.zookeeper-dispatch-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   This method emits PHP warning when callback could not be invoked.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.zookeeper-dispatch-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5705">
   <p><strong>Example #1 <span class="methodname"><strong>zookeeper_dispatch()</strong></span> example #1</strong></p>
   <div class="example-contents"><p>
     Dispatch callbacks manually.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Zookeeper</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost:2181'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'/zookeeper'</span><span style="color: #007700">,&nbsp;function()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Callback&nbsp;was&nbsp;called"</span><span style="color: #007700">.</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />});<br />while(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">zookeeper_dispatch</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 examples" id="refsect1-function.zookeeper-dispatch-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-5706">
   <p><strong>Example #2 <span class="methodname"><strong>zookeeper_dispatch()</strong></span> example #2</strong></p>
   <div class="example-contents"><p>
     Declare ticks.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">declare(</span><span style="color: #0000BB">ticks</span><span style="color: #007700">=</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Zookeeper</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost:2181'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'/zookeeper'</span><span style="color: #007700">,&nbsp;function()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Callback&nbsp;was&nbsp;called"</span><span style="color: #007700">.</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />});<br />while(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.zookeeper-dispatch-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="zookeeper.addauth.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::addAuth()</a> - Specify application credentials</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.connect.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::connect()</a> - Create a handle to used communicate with zookeeper</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.construct.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::__construct()</a> - Create a handle to used communicate with zookeeper</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.exists.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::exists()</a> - Checks the existence of a node in zookeeper synchronously</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.get.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::get()</a> - Gets the data associated with a node synchronously</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.getchildren.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::getChildren()</a> - Lists the children of a node synchronously</span></li>
    <li class="member"><span class="methodname"><a href="zookeeper.setwatcher.html" class="methodname" rel="rdfs-seeAlso">Zookeeper::setWatcher()</a> - Set a watcher function</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>